//
//  RYCAlertView.m
//  testapp
//
//  Created by hemingway payegis on 13-1-21.
//  Copyright (c) 2013年 payegis. All rights reserved.
//

#import "RYCAlertView.h"

@interface RYCAlertView ()
@property (nonatomic, copy) void (^operation)(NSInteger);
@end

@implementation RYCAlertView

- (void)dealloc
{
    self.operation = nil;
    [super dealloc];
}

- (void)showWithOperation:(void (^)(NSInteger clickedIndex))operation
{
    self.delegate = self;
    self.operation = operation;
    [self show];
}

+ (void)showHint:(NSString*)title message:(NSString*)message cancelButtonTitle:(NSString *)cancelButtonTitle operation:(void (^)(NSInteger clickedIndex))operation
{
    RYCAlertView* alertView = [[RYCAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil];
    [alertView showWithOperation:operation];
    [alertView release];
}

+ (void)showHint:(NSString*)title message:(NSString*)message operation:(void (^)(NSInteger clickedIndex))operation
{
    [RYCAlertView showHint:title message:message cancelButtonTitle:@"确认" operation:operation];
}

+ (void)showConfirm:(NSString*)title message:(NSString*)message operation:(void (^)(NSInteger clickedIndex))operation
{
    RYCAlertView* alertView = [[RYCAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
    [alertView showWithOperation:operation];
    [alertView release];
}

#pragma mark UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (_operation)
    {
        _operation(buttonIndex);
    }
}
@end
